<template>
	<div>
		<!-- 审批弹窗 -->
    <el-dialog 
      title="相关方评定计划审批"
      append-to-body
      :visible.sync="approveDialog"
      :close-on-click-modal="false" 
      :before-close="closeApproveDialog"
      width="60%"
      class="related_party_plan_approve_dialog"
    >
      <avue-form 
        ref="approveForm" 
        v-model="approveObj" 
        :option="approveOption" 
        @submit="confirmApproveRelatedParty"
      >
        <template slot="menuForm">
          <el-button 
            size="small"
            icon="el-icon-close"
            @click="closeApproveDialog()">
            取 消
          </el-button>
        </template>
      </avue-form>
    </el-dialog>
	</div>
</template>

<script>
import { getDetail, approveRelatedParty } from "@/api/basedata/interestedpartymange/relatedpartyjudgeplan";

export default {
  props: {
    approveDialog: {default: false},
    approvePartyId: {default: ""}
  },
  data() {
    return {
      approveObj: {}
    }
  },
  watch: {
    approveDialog(){
      if(this.approveDialog === true){
        this.initData();
      }
    }
  },
  computed: {
    approveOption() {
      return {
        size: "small",
        submitText: "审 批",
        mockBtn: false,
        printBtn: false,
        emptyBtn: false,
        column: [
          {
            label: "单位名称",
            prop: "xgfdw",
            disabled: true,
            type: "select",
            dicUrl: "/api/interestedPartyMange/relatedparty/list",
            props: {
              label: "dwmc",
              value: "id",
            },
            rules: [{
              required: true,
              message: "请选择相关方单位",
              trigger: "change"
            }]
          },
          {
            label: "主持人",
            prop: "pdzcr",
            disabled: true,
            rules: [{
              required: true,
              message: "请输入评定主持人",
              trigger: "blur"
            }]
          },
          {
            label: "合作项目清单",
            prop: "hzxmqd",
            disabled: true,
            type: "textarea",
            span: 24,
            maxlength: 150
          },
          {
            label: "评定人员",
            prop: "pdry",
            disabled: true,
            span: 24,
            type: "tree",
            multiple: true,
            checkStrictly: true,
            dicUrl: "/api/riskPoint/riskmanagement/getInternalStaff",
            props: {
              label: "realName",
              value: "id",
            },
            rules: [{
              required: true,
              message: "请选择评定人员",
              trigger: "change"
            }]
          },
          {
            label: "备注",
            prop: "bz",
            disabled: true,
            type: "textarea",
            span: 24,
            maxlength: 150
          },
          {
            label: "是否通过",
            prop: "passed",
            span: 24,
            type: "radio",
            dicData: [{
              label: "通过",
              value: 1
            }, {
              label: "不通过",
              value: 0
            }],
            rules: [{
              required: true,
              message: "请选择是否通过",
              trigger: "change"
            }]
          },
          {
            label: "审批意见",
            prop: "spyj",
            type: "textarea",
            span: 24,
            maxlength: 150,
          }
        ]
      }
    }
  },
  mounted() {
    this.initData();
  },
  methods: {

    // 初始化数据
    initData() {
      this.getRelatedPartyPlanDetail();
    },

    // 获取相关方评定计划详情
    getRelatedPartyPlanDetail() {
      getDetail(this.approvePartyId).then(res => {
        var resData = res.data.data;
        this.approveObj = this.formatApproveObj(resData);
      });
    },

    // 获取审批弹窗数据
    formatApproveObj(row) {
      var data = {};
      for(var key in row) {
        data[key] = row[key];
      }
      data["passed"] = "";
      data["spyj"] = "";
      return data;
    },

    // 关闭、取消审批弹窗
    closeApproveDialog() {
      this.$emit('closeApproveDialog');
    },

    // 确认审批
    confirmApproveRelatedParty() {
      this.$refs.approveForm.validate((vaild,done)=>{
        if(vaild){
          approveRelatedParty(this.approveObj.id, this.approveObj.passed, this.approveObj.spyj).then(res => {
            if(res.data.success) {
              this.$emit('confirmApproveRelatedParty');
            }
          });
          done();
        }
      })
    }

  }
}
</script>

<style lang="scss" scoped>
.approve_setting_footer {
  text-align: center;
  margin-top: 15px;

  .el-button {
    width: 100px;
    height: 35px;
  }
}
</style>